package com.zjitc.book.service.impl;

import com.zjitc.book.entity.MyUserDetails;
import com.zjitc.book.entity.Permissions;
import com.zjitc.book.entity.User;
import com.zjitc.book.mapper.UserMapper;
import com.zjitc.book.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.List;

@Service
public class UserServiceImpl implements UserDetailsService, UserInfoService {

    @Autowired
    UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userMapper.getUserByUsername(username);
        if(user == null){
            throw new UsernameNotFoundException("无法找到用户");
        }
        //todo:查用户权限
        List<String> authorities=userMapper.getPermissionByUsername(username);
        MyUserDetails userDetails = new MyUserDetails(user,authorities);
        return userDetails;
    }

    @Override
    public List<Permissions> getMenu() {
        userMapper.getMunu();
        return List.of();
    }
}










